import Router from '@koa/router';
import { validateDto } from '../../../middleware/validation';
import { AuthMiddleware } from '../../../middleware/authMiddleware';
import { RoleController } from '../../../controllers/system/roleController';
import { CreateRoleDto, UpdateRoleDto } from '../../../dtos/system/RoleDto';

const router = new Router();

const roleController = new RoleController();
const authMiddleware = new AuthMiddleware();

// 获取所有角色（需要认证）
router.get('/', authMiddleware.authenticate, roleController.getRoles);

// 根据ID获取角色（需要认证）
router.get('/:id', authMiddleware.authenticate, roleController.getRoleById);

// 创建角色（需要认证，仅管理员）
router.post('/', authMiddleware.authenticate, authMiddleware.requireRole('admin'), validateDto(CreateRoleDto), roleController.createRole);

// 更新角色（需要认证，仅管理员）
router.put('/:id', authMiddleware.authenticate, validateDto(UpdateRoleDto, { skipMissingProperties: true }), roleController.updateRole);

// 删除角色（需要认证，仅管理员）
router.delete('/:id', authMiddleware.authenticate, authMiddleware.requireRole('admin'), roleController.deleteRole);

export default router;